//
//  WLRouterWiFiSetController.m
//  WanLian
//
//  Created by muzhuang on 2018/10/18.
//  Copyright © 2018年 wanlian. All rights reserved.
//

#import "WLRouterWiFiSetController.h"
#import "WLRouterWiFiSubController.h"
#import "JXCategoryView.h"

@interface WLRouterWiFiSetController ()<JXCategoryViewDelegate>

@property (nonatomic, copy) NSArray *arrControllers;

@end

@implementation WLRouterWiFiSetController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"WiFi设置";
    
    NSArray *titleNameArr = @[@"2.4G",@"5G",@"访客网络"];
    
    CGFloat height = HEIGHT_SCREEN_WL-WL_NavTopHeight-WLScaleX(40);
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, WLScaleX(40), WIDTH_SCREEN_WL, height)];
    //    scrollView.delegate = self;
    scrollView.pagingEnabled = YES;
    scrollView.contentSize = CGSizeMake(WIDTH_SCREEN_WL*(titleNameArr.count), height);
    scrollView.bounces = NO;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:scrollView];
    
    JXCategoryTitleView *categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 0, WIDTH_SCREEN_WL, WLScaleX(40))];
    categoryView.backgroundColor = [UIColor whiteColor];
    categoryView.delegate = self;
    categoryView.titles = titleNameArr;
    categoryView.titleColor = wlLightTextColor;
    categoryView.titleSelectedColor = wlBlackColor;
    categoryView.cellWidth = WLScaleX(75);
    categoryView.titleFont = [WLCommonTool fontTypePingFangSCRegular:16];
    //2、添加并配置指示器
    //lineView
    JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
    lineView.indicatorLineViewColor = wlblueColor;
    lineView.indicatorLineWidth = WLScaleX(50);//JXCategoryViewAutomaticDimension;
    lineView.lineStyle = JXCategoryIndicatorLineStyle_IQIYI;
    //backgroundView
    //    JXCategoryIndicatorBackgroundView *backgroundView = [[JXCategoryIndicatorBackgroundView alloc] init];
    //    backgroundView.backgroundViewColor = [UIColor redColor];
    //    backgroundView.backgroundViewWidth = JXCategoryViewAutomaticDimension;
    categoryView.indicators = @[lineView];
    
    //3、绑定contentScrollView。self.scrollView的初始化细节参考源码。
    categoryView.contentScrollView = scrollView;
    [self.view addSubview:categoryView];
    
    WLRouterWiFiSubController *fourgVC = [[WLRouterWiFiSubController alloc] init];
    fourgVC.wifiType = 0;
//    fourgVC.wifiModel = self.wifiConfig;
    WLRouterWiFiSubController *fivegVC = [[WLRouterWiFiSubController alloc] init];
    fivegVC.wifiType = 1;
//    fivegVC.wifiModel = self.wifiConfig;
    WLRouterWiFiSubController *guestVC = [[WLRouterWiFiSubController alloc] init];
    guestVC.wifiType = 2;
//    guestVC.wifiModel = self.wifiConfig;
    NSArray *controllerArray = @[fourgVC,fivegVC,guestVC];
    self.arrControllers = controllerArray;
    
    for (int i = 0;  i<titleNameArr.count; i++) {
        UIViewController *controller = controllerArray[i];
        [self addChildViewController:controller];
        controller.view.frame = CGRectMake(WIDTH_SCREEN_WL*i, 0, WIDTH_SCREEN_WL, height);
        [scrollView addSubview:controller.view];
    }
    
//    if (self.wifiConfig.hasFiveConfig == 1) {
//        categoryView.defaultSelectedIndex = 1;
//    }
//    else if (self.wifiConfig.hasCustomerConfig==1)
//    {
//        categoryView.defaultSelectedIndex = 2;
//    }
}

#pragma mark - JXCategoryViewDelegate
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
    //侧滑手势处理
    //    if (_shouldHandleScreenEdgeGesture) {
    //        self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
    //    }
//    WLLog(@"____%d",index);
    WLRouterWiFiSubController *subContrller = self.arrControllers[index];
    [subContrller receiveRouterWifiAgain];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
